﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Globalization;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace QLKBNT
{
    /*public class KetNoi
    {
        OleDbConnection KetnoiOLE;
        OleDbCommand LenhThucThi;
        OleDbDataAdapter BangDuLieu;
        DataTable dt;

        string ChuoiKetNoi; //= Properties.Settings.Default.ConnectionString;

        public void MoKetNoi()
        {
            try
            {
                //Khai bao va thiet lap doi tuong ket noi
                KetnoiOLE = new OleDbConnection(ChuoiKetNoi);
                //Mo ket noi
                KetnoiOLE.Open();
            }
            catch (OleDbException Loi)
            {
                MessageBox.Show(Loi.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void DongKetNoi()
        {
            KetnoiOLE.Close();
        }

        public void ThucThiCauSQL(string SQL)
        {
            //Thuc thi cau lenh SQL
            LenhThucThi = new OleDbCommand(SQL, KetnoiOLE);
            LenhThucThi.ExecuteNonQuery();

        }

        public void ThucThiCauSQL_ChiDoc(string SQL)
        {

            //Thuc thi cau lenh SQL
            LenhThucThi = new OleDbCommand(SQL, KetnoiOLE);
            LenhThucThi.ExecuteReader();

        }

        public DataTable GoiBangDL(string SQL)
        {
            //Khoi tao doi tuong DataTable
            dt = new DataTable();
            //Khoi tao bảng bang cau SQL
            BangDuLieu = new OleDbDataAdapter(SQL, KetnoiOLE);
            //Gan bang vua tao vao Datatable
            BangDuLieu.Fill(dt);
            //Tra ve bang vua tao
            return dt;
        }

        public void DongForm()
        {
            frmBacSi frmbacsi = new frmBacSi();
            frmbacsi.Close();
            frmBaiThuocThang frmbaithuocthang = new frmBaiThuocThang();
            frmbaithuocthang.Close();
            frmChiDinhDichVu frmchidinhdichvu = new frmChiDinhDichVu();
            frmchidinhdichvu.Close();
            frmChonDichVu frmchondichvu = new frmChonDichVu();
            frmchondichvu.Close();
            frmDanhMuc_ChiDinh frmdanhmuc_chidinh = new frmDanhMuc_ChiDinh();
            frmdanhmuc_chidinh.Close();
            frmDanhSachChoKham frmdanhsachchokham = new frmDanhSachChoKham();
            frmdanhsachchokham.Close();
            frmDoiMatKhau frmdoimatkhau = new frmDoiMatKhau();
            frmdoimatkhau.Close();
            frmDonThuoc frmdonthuoc = new frmDonThuoc();
            frmdonthuoc.Close();
            frmNhanVien frmnhanvien = new frmNhanVien();
            frmnhanvien.Close();
            frmPhongKham frmphongkham = new frmPhongKham();
            frmphongkham.Close();
            frmSoThu_VienPhi frmsothu_vienphi = new frmSoThu_VienPhi();
            frmsothu_vienphi.Close();
            frmThuoc frmthuoc = new frmThuoc();
            frmthuoc.Close();
            frmThuVP frmthuvp = new frmThuVP();
            frmthuvp.Close();
            frmThuVP_BHYT frmthuvp_bhyt = new frmThuVP_BHYT();
            frmthuvp_bhyt.Close();
            frmThuVP_DV frmthuvp_dv = new frmThuVP_DV();
            frmthuvp_dv.Close();
            frmTiepNhan frmtiepnhan = new frmTiepNhan();
            frmtiepnhan.Close();
            frmBenh frmbenh = new frmBenh();
            frmbenh.Close();
            frmPhieuKhamBenh frmphieukhambenh = new frmPhieuKhamBenh();
            frmphieukhambenh.Close();
        }
    }*/
    
    public class KetNoi
    {
        public const string connectString = "Data Source = computer\\SQLEXPRESS;Initial Catalog=QLKBNT;Integrated Security=True";
        SqlDataAdapter adapter;
        SqlConnection connection;
        SqlCommand command;
        DataSet dataset = null;

        public KetNoi()
        {
        }

        //Kết nối CSDL
        public SqlConnection KetNoiCSDL()
        {
            return new SqlConnection(connectString);
        }

        //Lấy dữ liệu từ table
        public DataSet LayDuLieu(string sql)
        {
            try
            {
                connection = new SqlConnection(connectString);
                connection.Open();
                command = new SqlCommand(sql, connection);
                command.CommandType = CommandType.Text;
                adapter = new SqlDataAdapter(command);
                dataset = new DataSet();
                adapter.Fill(dataset, "Table[0]");
                command.Dispose();
                connection.Dispose();
            }
            catch
            {
                command.Dispose();
                connection.Dispose();
            }
            return dataset;
        }

        //Thực thi các câu lệnh Sql
        public bool ThuThiSql(string sql)
        {
            try
            {
                connection = new SqlConnection(connectString);
                connection.Open();
                command = new SqlCommand(sql, connection);
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();
                command.Dispose();
                connection.Dispose();
                return true;
            }
            catch
            {
                command.Dispose();
                connection.Dispose();
                return false;
            }
        }

        //Định dạng ngày tháng năm
        public System.DateTime StringToDate(string s)
        {
            string[] format = { "dd/MM/yyyy" };
            return System.DateTime.ParseExact(s.ToString(), format, System.Globalization.DateTimeFormatInfo.CurrentInfo, System.Globalization.DateTimeStyles.None);
        }

        //Hàm kiểm tra nhập ký tự là số
        public int KiemTraSo(string a)
        {
            int kq = 0;
            for (int i = 0; i < a.Length; i++)
            {
                if ((a[i] < (char)48 || (a[i] > (char)57))) // 48 = 0; 57 = 9
                {
                    kq = 1;
                    break;
                }
                else
                    kq = 0;
            }
            return kq;
        }
        public void DongForm()
        {
            frmBacSi frmbacsi = new frmBacSi();
            frmbacsi.Close();
            frmBaiThuocThang frmbaithuocthang = new frmBaiThuocThang();
            frmbaithuocthang.Close();
            frmChiDinhDichVu frmchidinhdichvu = new frmChiDinhDichVu();
            frmchidinhdichvu.Close();
            frmChonDichVu frmchondichvu = new frmChonDichVu();
            frmchondichvu.Close();
            frmDanhMuc_ChiDinh frmdanhmuc_chidinh = new frmDanhMuc_ChiDinh();
            frmdanhmuc_chidinh.Close();
            frmDanhSachChoKham frmdanhsachchokham = new frmDanhSachChoKham();
            frmdanhsachchokham.Close();
            frmDoiMatKhau frmdoimatkhau = new frmDoiMatKhau();
            frmdoimatkhau.Close();
            frmDonThuoc frmdonthuoc = new frmDonThuoc();
            frmdonthuoc.Close();
            frmNhanVien frmnhanvien = new frmNhanVien();
            frmnhanvien.Close();
            frmPhongKham frmphongkham = new frmPhongKham();
            frmphongkham.Close();
            frmSoThu_VienPhi frmsothu_vienphi = new frmSoThu_VienPhi();
            frmsothu_vienphi.Close();
            frmThuoc frmthuoc = new frmThuoc();
            frmthuoc.Close();
            frmThuVP frmthuvp = new frmThuVP();
            frmthuvp.Close();
            frmThuVP_BHYT frmthuvp_bhyt = new frmThuVP_BHYT();
            frmthuvp_bhyt.Close();
            frmThuVP_DV frmthuvp_dv = new frmThuVP_DV();
            frmthuvp_dv.Close();
            frmTiepNhan frmtiepnhan = new frmTiepNhan();
            frmtiepnhan.Close();
            frmBenh frmbenh = new frmBenh();
            frmbenh.Close();
            frmPhieuKhamBenh frmphieukhambenh = new frmPhieuKhamBenh();
            frmphieukhambenh.Close();
        }
    }

    public class Main_User
    {
           public   string  UserID;
           public string Nhom;  
           public string  UserName ;
           public string Pword ;        
           public DateTime NgayTao  ; 
           public DateTime UpdateDate   ;
           public DateTime NgayXoa; 
           public bool TrangThai ;
           public string GhiChu  ;
            public bool Bt00;
             public bool Bt10;
         public bool Bt11;
         public bool Bt12;
         public bool Bt20;
         public bool Bt21;
         public bool Bt22;
         public bool Bt23;
         public bool Bt30;
         public bool Bt31;
         public bool Bt32;
         public bool Bt33;
         public bool Bt40;
         public bool Bt41;
        public bool Bt411;
         public bool Bt412;
         public bool Bt42;
         public bool Bt43;
         public bool Bt44;
         public bool Bt45;
         public bool Bt46;
         public bool Bt47;
         public bool Bt50;
    }

  
    //public class Main_UserRight
    //{
    //    public string GroupID;
    //    public string UserID;
    //    public string FormID;
    //    public string ControlID;
    //    public bool PhanQuyen;
    //}
}
